libxc: Quieten the discard_file_cache() function. Preserve errno
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 28 Feb 2007 18:15:42 +0000 (18:15 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 28 Feb 2007 18:15:42 +0000 (18:15 +0000)
across it. No longer make calls to the function dependent on 'non-live
save/restore': it's not a good test of whether the fd is a socket.
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/libxc/xc_linux.c
tools/libxc/xc_linux_save.c
tools/libxc/xc_private.h
tools/libxc/xc_solaris.c

index 4874c042ddb0941556a6ecac33991396feb0ca27..eac5acc79369eade562cdfe31945703b0e5b0afd 100644 (file)
@@ -329,14 +329,15 @@ int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
 }
 
 /* Optionally flush file to disk and discard page cache */
-int discard_file_cache(int fd, int flush) 
+void discard_file_cache(int fd, int flush) 
 {
     off_t cur = 0;
+    int saved_errno = errno;
 
     if ( flush && (fsync(fd) < 0) )
     {
-        PERROR("Failed to flush file: %s", strerror(errno));
-        return -errno;
+        /*PERROR("Failed to flush file: %s", strerror(errno));*/
+        goto out;
     }
 
     /* 
@@ -354,11 +355,12 @@ int discard_file_cache(int fd, int flush)
     /* Discard from the buffer cache. */
     if ( posix_fadvise64(fd, 0, cur, POSIX_FADV_DONTNEED) < 0 )
     {
-        PERROR("Failed to discard cache: %s", strerror(errno));
-        return -errno;
+        /*PERROR("Failed to discard cache: %s", strerror(errno));*/
+        goto out;
     }
 
-    return 0;
+ out:
+    errno = saved_errno;
 }
 
 /*
index d8c87e3d95fb139fe013df4677b33127d583de89..77541030b5a70f87848f94e88ac07e2f4845063f 100644 (file)
@@ -178,20 +178,14 @@ static int noncached_write(int fd, int live, void *buffer, int len)
 
     int rc = write(fd,buffer,len);
 
-    if (!live) {
-        write_count += len;
+    write_count += len;
 
-        if (write_count >= MAX_PAGECACHE_USAGE*PAGE_SIZE) {
-            int serrno = errno;
-
-            /* Time to discard cache - dont care if this fails */
-            discard_file_cache(fd, 0 /* no flush */);
-
-            write_count = 0;
-
-            errno = serrno;
-        }
+    if (write_count >= MAX_PAGECACHE_USAGE*PAGE_SIZE) {
+        /* Time to discard cache - dont care if this fails */
+        discard_file_cache(fd, 0 /* no flush */);
+        write_count = 0;
     }
+
     return rc;
 }
 
@@ -1286,10 +1280,9 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
             DPRINTF("Warning - couldn't disable shadow mode");
         }
     }
-    else {
-        // flush last write and discard cache for file
-        discard_file_cache(io_fd, 1 /* flush */);
-    }            
+
+    // flush last write and discard cache for file
+    discard_file_cache(io_fd, 1 /* flush */);
 
     if (live_shinfo)
         munmap(live_shinfo, PAGE_SIZE);
@@ -1300,10 +1293,10 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
     if (live_p2m_frame_list)
         munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);
 
-    if(live_p2m)
+    if (live_p2m)
         munmap(live_p2m, P2M_SIZE);
 
-    if(live_m2p)
+    if (live_m2p)
         munmap(live_m2p, M2P_SIZE(max_mfn));
 
     free(pfn_type);
index 13935d361b2d4b89bf634e11c0760fd0270edbc1..7fa3258db11609b0ce8d36b1ad5e99dd953aef68 100644 (file)
@@ -166,6 +166,6 @@ void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
 void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
 
 /* Optionally flush file to disk and discard page cache */
-int discard_file_cache(int fd, int flush);
+void discard_file_cache(int fd, int flush);
 
 #endif /* __XC_PRIVATE_H__ */
index 4c537291e8109a1d39585c5c055e75732df78f07..65008115ead7dd48186d610d55553da771fe810c 100644 (file)
@@ -244,8 +244,7 @@ int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
 }
 
 /* Optionally flush file to disk and discard page cache */
-int discard_file_cache(int fd, int flush) 
+void discard_file_cache(int fd, int flush) 
 {
     // TODO: Implement for Solaris!
-    return 0;
 }